//
//  ToolbarWebsiteView.m
//  BaoVn
//
//  Created by Le Anh Tai on 11/19/14.
//  Copyright (c) 2014 Le Anh Tai. All rights reserved.
//

#import "ToolbarWebsiteView.h"

@implementation ToolbarWebsiteView

- (instancetype)init
{
    if (self = [super init])
    {
        _favoriteButton = [[UIButton alloc] init];
        [_favoriteButton setImage:[UIImage imageNamed:@"icon_favorite.png"] forState:UIControlStateNormal];
        [_favoriteButton setImage:[UIImage imageNamed:@"icon_favorite_hl.png"] forState:UIControlStateSelected];
        [_favoriteButton addTarget:self action:@selector(favoriteButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_favoriteButton];
        
        _shareButton = [[UIButton alloc] init];
        [_shareButton setImage:[UIImage imageNamed:@"icon_share.png"] forState:UIControlStateNormal];
        [_shareButton addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_shareButton];
        
        _fontButton = [[UIButton alloc] init];
        [_fontButton setImage:[UIImage imageNamed:@"icon_increase_font.png"] forState:UIControlStateNormal];
        [_fontButton addTarget:self action:@selector(fontButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_fontButton];
        
        _brightButton = [[UIButton alloc] init];
        [_brightButton setImage:[UIImage imageNamed:@"icon_bright.png"] forState:UIControlStateNormal];
        [_brightButton addTarget:self action:@selector(brightButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_brightButton];
    }
    
    return self;
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
    NSInteger wid = self.height;
    
    _brightButton.frame = RECT(self.width - wid, 0, wid, wid);
    _fontButton.frame = RECT(self.width - _brightButton.width - wid, 0, wid, wid);
    _shareButton.frame = RECT(self.width - _brightButton.width - _fontButton.width - wid, 0, wid, wid);
    _favoriteButton.frame = RECT(self.width - _brightButton.width - _fontButton.width - _shareButton.width - wid, 0, wid, wid);
}

- (void)favoriteButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarWebsiteDidPressFavoriteButton:)])
    {
        [_delegate toolbarWebsiteDidPressFavoriteButton:self];
    }
}

- (void)shareButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarWebsiteDidPressShareButton:)])
    {
        [_delegate toolbarWebsiteDidPressShareButton:self];
    }
}

- (void)fontButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarWebsiteDidPressFontButton:)])
    {
        [_delegate toolbarWebsiteDidPressFontButton:self];
    }
}

- (void)brightButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarWebsiteDidPressBrightButton:)])
    {
        [_delegate toolbarWebsiteDidPressBrightButton:self];
    }
}

@end
